import {
  getAllListData
} from '@/api/system/menu'

const state = () => ({
  menulist: [] // 菜单树
})

const getters = {
  menulist: state => state.menulist
}

const mutations = {
  // 设置菜单树数据
  SET_MENU_LIST (state, data) {
    state.menulist = data
  }
}

const actions = {
  // 请求菜单列表
  async getAllMenuList ({ commit, dispatch }) {
    const res = await getAllListData()
    commit('SET_MENU_LIST', res)
    // 请求菜单列表的时候，必须要重新获取用户信息！ 让用户的菜单数据保持最新！
    // dispatch('user/get_user_info', null, { root: true })
  }
}

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}
